<?php
declare (strict_types = 1);

namespace app\admin\controller;
use app\BaseController;
use think\facade\Db;
use think\facade\Request;
use think\facade\View;

class Pinp extends BaseController
{
    public function pinpaiList()
    {
        $keywords = Request::post('keywords');
        $post = Request::post();

        $whereOr=[];
        $where=[];
        if (isset($keywords) && $keywords<>'') $where[]=['brand_name','like',"%{$keywords}%"];
        if (isset($post['if_show']) && $post['if_show']<>'') $where[]=['if_show','=',$post['if_show']];
        if (isset($post['recommended']) && count($post['recommended'])==1)$where[]=['recommended','in',$post['recommended']];
        if (isset($post['brand_logo']) && count($post['brand_logo'])==1){
            if ($post['brand_logo'][0]==1){
                $where[]=['brand_logo','<>',''];
            }

            if ($post['brand_logo'][0]==2){
                $whereOr[]=['brand_logo','=',null];
                $whereOr[]=['brand_logo','=',''];
            }
        }

        $pinp=Db::table('ecm_brand')
            ->where($where)
            //->whereOr($whereOr)
            ->where(function ($q) use($whereOr){
                $q->whereOr($whereOr);})
            ->order('sort_order')
            ->select();
        View::assign('pinp',$pinp);
        View::assign($post);
        return view();
    }
}